package cn.wolfcode.mp.service.impl;


import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.mapper.EmployeeMapper;
import cn.wolfcode.mp.query.EmployeeQuery;
import cn.wolfcode.mp.query.QueryObject;
import cn.wolfcode.mp.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * mybatis-plus 服务层接口实现类
 * 1.自定义一个类EmployeeServiceImpl 继承ServiceImpl 实现自定义服务接口IEmployeeService
 * 2.在ServiceImpl上，明确指定两个泛型：1.当前操作实体对象对应mapper接口EmployeeMapper，2当前操作实体对象 Employee
 */

@Service
@Transactional
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper,Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Page<Employee> queryPage(EmployeeQuery qo) {

        QueryWrapper<Employee> wrapper = new QueryWrapper<>();
        Page<Employee> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());
        /*if(StringUtils.hasText(qo.getKeyword())){
            wrapper.like("name","明");
        }*/
        // 等价于上面
        wrapper.like(StringUtils.hasText(qo.getKeyword()),"name","明");
        return super.page(page,wrapper);
    }
}
